﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using PNProject.Core;
using PNProject.Core.Converter;
using PNProject.Models;
using PNProject.EF;

namespace PNProject.Controllers
{
    public class AdminEmailController : Controller
    {
        //
        // GET: /Email/

        public ActionResult Index(string p)
        {
            int page = 1;
            try
            {
                page = int.Parse(p);
            }
            catch (Exception e)
            {

            }
            var count = StaticData.emailRepo.GetAll().Count();
            var list = StaticData.emailRepo.GetSome(a => a.EmailID > 0, 20, (page - 1) * 20);
            List<EmailModel> model = new List<EmailModel>();
            foreach (var item in list)
            {
                EmailModel mail = new EmailModel()
                {
                    EmailID = item.EmailID,
                    Email = item.Email
                };
                model.Add(mail);
            }
            ViewData["page-total"] = count;
            ViewData["page-active"] = page;
            ViewData["page-list"] = PNLibraries.GetShowedPage(count, page,20, 5);
            return View(model);
        }

    }
}
